#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>

typedef int BTreeDataType;

typedef struct BTreeNode
{
	BTreeDataType val;
	struct BTreeNode* left;
	struct BTreeNode* right;
}BTreeNode;

BTreeNode* BuyBTreeNode(BTreeDataType x)
{
	BTreeNode* NewBTreeNode = (BTreeNode*)malloc(sizeof(BTreeNode));
	if (NewBTreeNode == NULL)
	{
		perror("malloc");
		return NULL;
	}
	NewBTreeNode->val = x;
	NewBTreeNode->left = NULL;
	NewBTreeNode->right = NULL;
	return NewBTreeNode;
}

BTreeNode* BTreeFind(BTreeNode *root ,BTreeDataType x)
{
	if (root == NULL)
	{
		return NULL;
	}
	if (root->val == x)
	{
		return root;
	}
	BTreeNode* lret = BTreeFind(root->left,x);
	if (lret)
		return lret;
	BTreeNode* rret = BTreeFind(root->right,x);
	if (rret)
		return rret;
	return NULL;
}

int main()
{
	BTreeNode* node1 = BuyBTreeNode(2);
	BTreeNode* node2 = BuyBTreeNode(5);
	BTreeNode* node3 = BuyBTreeNode(1);
	BTreeNode* node4 = BuyBTreeNode(3);
	BTreeNode* node5 = BuyBTreeNode(6);
	BTreeNode* node6 = BuyBTreeNode(4);

	node1->left = node2;
	node1->right = node3;
	node3->left = node4;
	node4->left = node5;
	node5->right = node6;
	BTreeNode* node=BTreeFind(node1,3);


	return 0;
}